/**
 * BannerController
 *
 * 主要职责：
 * - 轮播图（Banner）管理：上传图片、排序、上下线、列表查询
 *
 * 关键接口示例：
 * - Response uploadBanner(MultipartFile file, BannerDto dto)
 *
 * 依赖项：
 * - IBannerService、MinioService
 *
 * 答辩要点：
 * - 图片上传流程、排序事务性更新、缓存与 CDN 的结合
 */
package net.zjitc.yqmusicserver.controller;



import net.zjitc.yqmusicserver.domain.Banner;
import net.zjitc.yqmusicserver.domain.dto.BannerDTO;
import net.zjitc.yqmusicserver.domain.vo.BannerVO;
import net.zjitc.yqmusicserver.result.PageResult;
import net.zjitc.yqmusicserver.result.Result;
import net.zjitc.yqmusicserver.service.IBannerService;
import net.zjitc.yqmusicserver.service.MinioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import java.util.List;

@RestController
public class BannerController {

    @Autowired
    private IBannerService bannerService;
    @Autowired
    private MinioService minioService;

    /**
     * 获取轮播图列表
     *
     * @return 轮播图列表
     */
    @PostMapping("/admin/getAllBanners")
    public Result<PageResult<Banner>> getAllBanners(@RequestBody BannerDTO bannerDTO) {
        return bannerService.getAllBanners(bannerDTO);
    }

    /**
     * 添加轮播图
     *
     * @param banner 轮播图
     * @return 结果
     */
    @PostMapping("/admin/addBanner")
    public Result addBanner(@RequestParam("banner") MultipartFile banner) {
        String bannerUrl = minioService.uploadFile(banner, "banners");
        return bannerService.addBanner(bannerUrl);
    }

    /**
     * 更新轮播图
     *
     * @param banner 轮播图
     * @return 结果
     */
    @PatchMapping("/admin/updateBanner/{id}")
    public Result updateBanner(@PathVariable("id") Long bannerId, @RequestParam("banner") MultipartFile banner) {
        String bannerUrl = minioService.uploadFile(banner, "banners");
        return bannerService.updateBanner(bannerId, bannerUrl);
    }

    /**
     * 更新轮播图状态
     *
     * @param bannerStatus 轮播图状态
     * @return 结果
     */
    @PatchMapping("/admin/updateBannerStatus/{id}")
    public Result updateBannerStatus(@PathVariable("id") Long bannerId, @RequestParam("status") Integer bannerStatus) {
        return bannerService.updateBannerStatus(bannerId, bannerStatus);
    }

    /**
     * 删除轮播图
     *
     * @param bannerId 轮播图id
     * @return 结果
     */
    @DeleteMapping("/admin/deleteBanner/{id}")
    public Result deleteBanner(@PathVariable("id") Long bannerId) {
        return bannerService.deleteBanner(bannerId);
    }

    /**
     * 批量删除轮播图
     *
     * @param bannerIds 轮播图id列表
     * @return 结果
     */
    @DeleteMapping("/admin/deleteBanners")
    public Result deleteBanners(@RequestBody List<Long> bannerIds) {
        return bannerService.deleteBanners(bannerIds);
    }

    /**
     * 获取轮播图列表（用户端）
     *
     * @return 轮播图列表
     */
    @GetMapping("/banner/getBannerList")
    public Result<List<BannerVO>> getBannerList() {
        return bannerService.getBannerList();
    }
}
